package com.newjiabo.ski.service.impl;

import java.util.List;

import com.newjiabo.common.utils.DateUtils;
import com.newjiabo.ski.domain.vo.CameramanInfoVo;
import com.newjiabo.ski.service.ISkiCameramanRequestNoteService;
import com.newjiabo.ski.service.ISkiMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.newjiabo.ski.mapper.SkiCameramanMapper;
import com.newjiabo.ski.domain.SkiCameraman;
import com.newjiabo.ski.service.ISkiCameramanService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 摄影师Service业务层处理
 *
 * @author CaoMengHui
 * @date 2023-10-18
 */
@Service
public class SkiCameramanServiceImpl implements ISkiCameramanService {
    @Resource
    private SkiCameramanMapper skiCameramanMapper;
    @Resource
    private ISkiMemberService memberService;
    @Resource
    private ISkiCameramanRequestNoteService cameramanRequestNoteService;

    /**
     * 查询摄影师
     *
     * @param id 摄影师主键
     * @return 摄影师
     */
    @Override
    public SkiCameraman selectSkiCameramanById(String id) {
        return skiCameramanMapper.selectSkiCameramanById(id);
    }

    /**
     * 查询摄影师列表
     *
     * @param skiCameraman 摄影师
     * @return 摄影师
     */
    @Override
    public List<SkiCameraman> selectSkiCameramanList(SkiCameraman skiCameraman) {
        return skiCameramanMapper.selectSkiCameramanList(skiCameraman);
    }

    /**
     * 新增摄影师
     *
     * @param skiCameraman 摄影师
     * @return 结果
     */
    @Override
    public int insertSkiCameraman(SkiCameraman skiCameraman) {
        skiCameraman.setCreateTime(DateUtils.getNowDate());
        return skiCameramanMapper.insertSkiCameraman(skiCameraman);
    }

    /**
     * 修改摄影师
     *
     * @param skiCameraman 摄影师
     * @return 结果
     */
    @Override
    public int updateSkiCameraman(SkiCameraman skiCameraman) {
        skiCameraman.setUpdateTime(DateUtils.getNowDate());
        return skiCameramanMapper.updateSkiCameraman(skiCameraman);
    }

    /**
     * 批量删除摄影师
     *
     * @param ids 需要删除的摄影师主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteSkiCameramanByIds(String[] ids) {
        // 先更新会员信息
        memberService.resetCameramanByIds(ids);
        return skiCameramanMapper.deleteSkiCameramanByIds(ids);
    }

    /**
     * 删除摄影师信息
     *
     * @param id 摄影师主键
     * @return 结果
     */
    @Override
    public int deleteSkiCameramanById(String id) {
        return skiCameramanMapper.deleteSkiCameramanById(id);
    }

    @Override
    public CameramanInfoVo info(String id) {
        SkiCameraman skiCameraman = this.selectSkiCameramanById(id);
        String requestNoteId = skiCameraman.getRequestNoteId();
        CameramanInfoVo cameramanInfoVo = new CameramanInfoVo(skiCameraman,
                cameramanRequestNoteService.selectSkiCameramanRequestNoteById(requestNoteId),
                memberService.selectSkiMemberById(skiCameraman.getMemberId()));
        return cameramanInfoVo;
    }
}
